package com.yc.thread.pro1_matrix.individual;

/**
 * @author zwei
 * @create 2024-07-16 17:41
 */
public class individualMultiplierTask implements Runnable{
    private final double[][]result;     //final：确保线程的安全性
    private final double[][]matrix1;
    private final double[][]matrix2;
    private final int row;
    private final int column;

    /**
     *
     * @param result:结果矩阵
     * @param matrix1：矩阵A
     * @param matrix2：矩阵B
     * @param i：结果矩阵的第i行
     * @param j：结果矩阵的第j列
     */
    public individualMultiplierTask(double[][] result, double[][] matrix1, double[][] matrix2, int i, int j) {
        this.result=result;
        this.matrix1=matrix1;
        this.matrix2=matrix2;
        this.row=i;
        this.column=j;
    }

    @Override
    public void run() {
        result[row][column]=0;
        //累加求和
        for (int k = 0; k < matrix1[row].length; k++) {
            result[row][column]+=matrix1[row][k]*matrix2[k][column];
        }
    }
}
